var global_taskId;
var global_mainId;
var global_from;
function reportTask(taskId,mainId,from){
	//var datas = getdata("form"+task_id);
	//var mainId = $("#mainId").val();
	global_taskId = taskId;
	global_mainId = mainId;
	global_from = from;
	if(mainId==""){
		alert("请先保存基本信息!");
		return;
	}
	$.ajax( {
   			type : 'POST',
   			url :"/FPM/report/saveTaskInfo?mainId="+mainId+"&task_id="+taskId+"&fromDown=1",
   			cache : false,
   			async:false,
   			data:$('#taskForm'+taskId).serialize(),
   			error: function(XMLHttpRequest, textStatus, errorThrown) {
   				//alert(XMLHttpRequest.readyState);
   			},
   			success : function(result) {
   				$("input[type=text]").css("border","1px solid #C1DAD7");
   				if(result=="success"){
   					//isReported();
   					//alert("保存成功!");
   					//window.location="${pageContext.request.contextPath}/report/toModify?selIds="+mainId+"&fromDown=${fromDown}"+"&taskId="+task_id;
   					reportTask1(global_taskId,global_mainId,global_from);
   				}else{
   					var wrongId = result.split(",")[1];
   					var taskId = result.split(",")[2];
   					if(result.split(",")[0]=="wrong"){
   						$("#task"+taskId).find("#"+wrongId).css("border","1px solid red");
	   					alert("上报数据有误,请核对!");
	   					return;
   					}else{
   						alert("请填写数据!");
   						return;
   					}	
   				}
   			}
   		});
	
}
function reportTask1(taskId,mainId,from){
	$.ajax( {
		type : 'GET',
		url :"/FPM/report/reportTask?taskId="+taskId+"&mainId="+mainId,
		cache : false,
		async:false,
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert(XMLHttpRequest.readyState);
		},
		success : function(result) {
			if(result=="success"){
				alert("上报成功!");
				$("#reportTask").hide();
				$("#approveTask").show();
				$("#rejectTask").show();
				window.location="/FPM/report/toModify?selIds="+mainId+"&fromDown="+from;
			}
		}
	});
}

function approvalTask(taskId,mainId,approvalStatus){
	$.ajax( {
			type : 'GET',
			url :"/FPM/report/approvalTask?taskId="+taskId+"&mainId="+mainId+"&approvalStatus="+approvalStatus,
			cache : false,
			async:false,
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				alert(XMLHttpRequest.readyState);
			},
			success : function(result) {
				if(result=="success"){
					alert("审批成功!");
					$("#reportTask").hide();
					$("#approveTask").show();
					$("#rejectTask").show();
					window.location="/FPM/report/toModify?selIds="+mainId+"&fromDown=0";
				}
			}
		});
}